package com.guguju.ssms.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.guguju.ssms.R;

/**
 * Created by dell on 2022-5-17.
 */
public class ProgressLogoView extends FrameLayout {
    /**
     * 旋转的外层圆
     */
    ImageView mIvProgressRotate;
    RotateAnimation rotateAnimationLogo;

    public ProgressLogoView(Context context) {
        super(context);
        init();
    }

    public ProgressLogoView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ProgressLogoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {

        View.inflate(getContext(), R.layout.view_progress_logo, this);
        mIvProgressRotate = (ImageView) findViewById(R.id.progress_logo_rotate);
        rotateAnimationLogo = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimationLogo.setRepeatCount(Animation.INFINITE);
        rotateAnimationLogo.setDuration(1000);
        mIvProgressRotate.setAnimation(rotateAnimationLogo);
        rotateAnimationLogo.start();
    }

    /**
     * 展现
     */
    public void showProgress() {

        if (!isShown()) {
            setVisibility(View.VISIBLE);
        }
    }

    /**
     * 消失
     */
    public void hideProgress() {
        if (isShown()) {
            setVisibility(View.GONE);
        }
    }
}
